from django.db import models
import copy
from simdb.models import  MetadataObject, Protocol, Snapshot, Property
from simdb.base import DATA_TYPES

class FileType(MetadataObject):
    _collection_sets = []
    protocol = models.ForeignKey(Protocol)
    name = models.CharField(max_length=1024)
    description = models.TextField(blank=True)    
    mime_type = models.CharField(max_length=256, blank=True)
    _container_field = "protocol_id"
    Protocol._collection_sets.append('filetype_set')

class File(MetadataObject):
    _collection_sets = []
    snapshot = models.ForeignKey(Snapshot)
    publisherDID = models.CharField(max_length=1024)
    filetype = models.ForeignKey(FileType, blank=True)
    mime_type = models.CharField(max_length=256)
    # size in bytes, KiB?
    size = models.PositiveIntegerField(default=0)
    href = models.URLField(verify_exists=False)
    _container_field = "snapshot_id"
    Snapshot._collection_sets.append('file_set')   

class Array(MetadataObject):
    _collection_sets = []
    file = models.ForeignKey(File)
    property = models.ForeignKey(Property)
    rank = models.PositiveIntegerField(default=1, blank=True)
    offset = models.PositiveIntegerField(default=0, blank=True)
    stride = models.PositiveIntegerField(default=1, blank=True)
    skipbyte = models.PositiveIntegerField(default=0, blank=True)
    endian = models.CharField(max_length=256, 
                              choices=(('BIG', 'Big endian'),
                                       ('LITTLE', 'Little endian')), blank=True)
    row_major = models.BooleanField(default=True, blank=True)
    internal_path = models.CharField(max_length=1024, blank=True)
    # lazy, support only up to 3 dimensions
    left_edge0 = models.FloatField(default=0.0, blank=True)
    left_edge1 = models.FloatField(default=0.0, blank=True)
    left_edge2 = models.FloatField(default=0.0, blank=True)
    right_edge0 = models.FloatField(default=1.0, blank=True)
    right_edge1 = models.FloatField(default=1.0, blank=True)
    right_edge2 = models.FloatField(default=1.0, blank=True)
    _container_field = "file_id"
    File._collection_sets.append('array_set')   
